import Vue from 'vue'
import Vuex from 'vuex'
import {getUserMsg} from "../api/api"

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    isLogin: true,
    forgetIsLogin: false,
    userInfo:"",
  },
  mutations: {
    changeLogin(state, payload) {
      state.isLogin = payload.isLogin
      state.userInfo = payload.userInfo
      
    },
    changfogetcode(state,payload){
      state.isLogin=payload.isLogin
    },
    changeforgetIsLogin(state,payload){
      state.forgetIsLogin=payload.forgetIsLogin
    },
  },
  actions: {
    checkLogin(context) {
      getUserMsg().then(res => {
        console.log(res)
        if (res.code == 0){

          context.commit("changeLogin",{isLogin:false,userInfo:res.userInfo})

        }
      })
    }
  },
  modules: {
  }
})
